package com.edu.koTA07.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.edu.koTA07.bean.BarangBean;
import com.edu.koTA07.bean.PesananDetailBean;
import com.edu.koTA07.takingOrder.R;
import com.edu.koTA07.utils.BarangUtils;

public class MenuPesananListAdapter extends BaseAdapter{

	ArrayList<PesananDetailBean> pesananDetails;
	List<BarangBean> listBarangCurrent;
	BarangUtils util;
	//PesananDetailUtils utilPesananDetail;
	Context context;
	// private ImageLoader imageLoader;
	public MenuPesananListAdapter(Context context,
			ArrayList<PesananDetailBean> pesananDetails) {
		// TODO Auto-generated constructor stub
		super();
		inflater = (LayoutInflater) context
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.pesananDetails = pesananDetails;
		this.context = context;
	}
	private static LayoutInflater inflater = null;

	public int getCount() {
		return pesananDetails.size();
	}

	public PesananDetailBean getItem(int position) {
		return (null == pesananDetails) ? null : pesananDetails.get(position);
	}
	
	public ArrayList<PesananDetailBean> getItemAll() {
		return (null == pesananDetails) ? null : pesananDetails;
	}

	public long getItemId(int position) {
		return position;
	}
	
	class ViewHolder {
		TextView textLine;
		TextView price;
		TextView kuantitasBarang;
		TextView subtotal;
		TextView potongan;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		View vi = convertView;
		util = new BarangUtils(context);
		
		if (convertView == null) {
			vi = inflater.inflate(R.layout.content_menu_pesanan, null);
			holder = new ViewHolder();
			holder.textLine = (TextView) vi.findViewById(R.id.isi_produk);
			holder.price = (TextView) vi.findViewById(R.id.isi_price);
			holder.kuantitasBarang = (TextView) vi.findViewById(R.id.isi_kuantitas);
			holder.subtotal = (TextView) vi.findViewById(R.id.isi_subtotal);
			holder.potongan = (TextView) vi.findViewById(R.id.isi_potongan);
			vi.setTag(holder);
		}
		else 
			holder = (ViewHolder) vi.getTag();
		
		//utilPesananDetail.loadData();
		BarangBean barangbean = util.getBarangById(pesananDetails.get(position).getIDBarang());

		holder.textLine.setText(barangbean.getNamaBarang());
		holder.price.setText(""+barangbean.getHargaBarang());
		holder.kuantitasBarang.setText(""+pesananDetails.get(position).getKuantitasPesanan());
		
		
		holder.subtotal.setText(""+pesananDetails.get(position).getTotal());
		holder.potongan.setText(""+pesananDetails.get(position).getPotongan());
		
		
		
		
		
        
        return vi;
	}


	
	public void forceReload() {
		notifyDataSetChanged();
	}	
}
